package com.heima.wemedia.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMQConfig {
    //延迟交换机
    public static final String DELAYED_EXCHANGE = "article.delayed.exchange";
    // 队列名称
    public static final String DELAYED_QUEUE = "article.delayed.queue";
    // 路由键
    public static final String DELAYED_ROUTING_KEY = "article.delayed.routingkey";

    @Bean
    public CustomExchange lazyExchange(){

        //第一种设置方法  设置延迟交换机配置
        Map<String, Object> pros = new HashMap<>();
        //设置交换机支持延迟消息推送
        pros.put("x-delayed-type", "topic");
        CustomExchange exchange = new CustomExchange(DELAYED_EXCHANGE, "x-delayed-message",true, false,pros);
        return exchange;
    }
    @Bean
    public Queue lazyQueue(){
        return new Queue(DELAYED_QUEUE ,true);
    }
    @Bean
    public Binding delayQueueBinding(){
        return BindingBuilder.bind(lazyQueue()).to(lazyExchange()).with(DELAYED_ROUTING_KEY).noargs();
    }
}
